/**
 * 
 */
package com.nars.objects;

/**
 * @author Student
 * 
 */
public class FinallizerExamples {
	private String name;

	public FinallizerExamples() {
		System.out.println("Object Created!!!");
	}

	public static void main(String[] args) throws Throwable {

		for (int i = 0; i < 1000000; i++)
			new FinallizerExamples();
		
	/*	{
			FinallizerExamples example = new FinallizerExamples();
//			System.gc();
			example = null;
		}
		{
			FinallizerExamples example2 = new FinallizerExamples();
			//System.gc();
			example2 = null;
		}
		{
			FinallizerExamples example3 = new FinallizerExamples();
			//System.gc();
			example3 = null;
		}
		System.gc();*/
		//System.gc();
		// System.gc();
		/*
		 * // example.finalize(); FinallizerExamples example2 = new
		 * FinallizerExamples(); // example2.finalize(); FinallizerExamples
		 * example3 = new FinallizerExamples(); // example3.finalize();
		 */
		// System.gc();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#finalize()
	 */
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		System.out.println("Object detroyed!!!");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FinallizerExamples other = (FinallizerExamples) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
}
